//
//  U9VideoManager.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/4/20.
//  Copyright © 2017年 Jason. All rights reserved.
//

#import "U9VideoManager.h"
#import "U9VideoModel.h"

@implementation U9VideoManager

+ (void)getVideoWithGid:(NSString *)gid andTitle:(NSString *)theme andLastDate:(NSString *)lastdate andCompletionHandle:(void(^)(U9VideoModel *model,NSError *error))complete{
    PlistStorage *plist = [PlistStorage sharedPlistStorage];
    if ([theme isEqualToString:@"推荐"]) {
        theme = @"";
    }
    if (IsNilOrNull(lastdate)) {
        lastdate = @"0";
    }
    NSString *encodingTheme = [theme stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *url = [NSString stringWithFormat:@"%@%@?cid=%@&lastdate=%@&t=0&k=%@",Api_URL,kGetVideos,gid,lastdate,encodingTheme];
    [self POST:url
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9VideoModel *video = [U9VideoModel mj_objectWithKeyValues:responseObj];
    if (video.error_code != 0) {
        error = [self createError:video.error_msg];
        video = [U9VideoModel mj_objectWithKeyValues:[plist readFromPlist:@"VideoList"]];
    } else if (error) {
        video = [U9VideoModel mj_objectWithKeyValues:[plist readFromPlist:@"VideoList"]];
    } else {
        [plist storageToPlist:responseObj andFileName:@"VideoList"];
    }
    complete(video,error);
    
}];
    
    
}

@end
